package com.koron.css2.newProjectCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.PjDelay;
import com.koron.css2.newProjectCenter.bean.PjInfoBean;
import com.koron.css2.newProjectCenter.bean.query.PjDelayQuery;
import com.koron.css2.newProjectCenter.bean.query.PjInfoQueryBean;
import com.koron.css2.newProjectCenter.mapper.PjDelayMapper;
import com.koron.css2.newProjectCenter.mapper.PjInfoMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

public class PjDelaySingle implements ServerInterface {
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            PjDelayQuery pjDelayQuery = JsonUtils.objectToPojo(req.getData(),PjDelayQuery.class);
            PjDelayMapper pjDelayMapper = factory.getMapper(PjDelayMapper.class);
            PjInfoMapper pjInfoMapper = factory.getMapper(PjInfoMapper.class);

            // 1. 查询数据
            PjDelay pjDelay = pjDelayMapper.getSingle(pjDelayQuery);
            // 2. 查询对应的工程报装
            PjInfoQueryBean pjInfoQueryBean = new PjInfoQueryBean();
            pjInfoQueryBean.setBillNo(pjDelay.getPjBillNo());
            PjInfoBean pjInfoBean = pjInfoMapper.getSingle(pjInfoQueryBean);
            // 3. 返回工程报装id（兼容前端）
            pjDelay.setConsultId(pjInfoBean.getId());
            // 4. 返回结果
            MessageBean<PjDelay> messageBean = MessageBean.create(Constant.MESSAGE_INT_SUCCESS,"延期详情查询成功", PjDelay.class);
            messageBean.setData(pjDelay);
            return messageBean;
        } catch (Exception e) {
            logger.error("延期详情查询失败",e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL,"延期详情查询失败",null);
        }
    }
}
